package GUI;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

import javax.swing.table.AbstractTableModel;

import Control.Ctr;
import Model.Invoice;

public class InvoiceTable extends AbstractTableModel {

private static final String[] columnNames = { "ID", "Date", "Client Name", "Court", "Coach", "Price" };
private Ctr ctr;

private ArrayList<Invoice> Invoice;
public InvoiceTable(){
	Invoice = new ArrayList<Invoice>();
	ctr = new Control.Ctr();

	for(Invoice e : ctr.findAllInvoice() )
	{Invoice.add(e);
	}
}
public InvoiceTable(String date)
{	
	
	ctr = new Control.Ctr();
	Invoice = new ArrayList<Invoice>();
	for(Invoice e :ctr.findAllInvoice())
	{if(e.getDate().equals(date))
		Invoice.add(e);}
	}

@Override
public int getColumnCount() {
    // 
    return columnNames.length;
}

@Override
public int getRowCount() {
    return Invoice.size();
}

@Override
public String getColumnName(int column) {
    return columnNames[column];
}

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
     {
    	switch (columnIndex){
   case 0:
        return Invoice.get(rowIndex).getiID();
    case 1:
    	return Invoice.get(rowIndex).getDate();
    case 2:
    	Model.Client c = ctr.findBycID(Invoice.get(rowIndex).getcID());
    	String s = c.getFname() + " " + c.getLname();
        return s;
    case 3:
    	Model.Court co = ctr.findBycoID(Invoice.get(rowIndex).getCoID());
    	String cos = co.getCo_name();
        return cos;
    case 4:
    	Model.Coach ch = ctr.findBychID(Invoice.get(rowIndex).getchID());
    	String chs = ch.getName();
    	return chs;
    case 5:
    	return Invoice.get(rowIndex).getPrice();
    			}
    }
    
    return null;
}   
}
